<template>
  <div>
    <el-container>
      <el-header>
        <div  class="firstSytle">
          <el-button size="mini" type="success" @click="initData"   icon="el-icon-refresh">刷新</el-button>
          <el-button size="mini" type="danger" @click="clearRecord"  icon="el-icon-delete">清空记录</el-button>
        </div>
      </el-header>

      <el-main style="padding-left: 1px;padding-top: 0px;height:100%">
        <div>
          <el-table :data="losts" stripe v-loading="tableLoading" size="mini" style="width: 100%;">
            <el-table-column prop="listId" label="序号" width="80px" align="center"></el-table-column>
            <el-table-column prop="id" label="失物编号"></el-table-column>
            <el-table-column prop="content" label="失物描述"></el-table-column>
            <el-table-column prop="creater" label="发布者"></el-table-column>
            <el-table-column prop="imgUrl" label="图片"></el-table-column>
            <el-table-column prop="createTime" label="发布时间"></el-table-column>
          </el-table>
          <div class="lastLine" style="margin-top: 10px">               
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                           :current-page.sync="pageNum" :page-sizes="[10, 20,30,50,100,200,]"
                           :page-size="pageSize"
                           layout="sizes, prev, pager, next" :total="total">      
            </el-pagination>
          </div>
        </div>
      </el-main>
    </el-container>
  </div>

</template>

<script>
    import {postMethod} from "../../utils/api";

    export default {
        data() {
            return {
                losts: [],
                tableLoading: false,
                pageNum: 1,
                pageSize: 10,
                total: 0,
                clickAddButton:false,
                list: [],
            };
        },
        methods: {
            initData: function () {
                this.tableLoading = true;
                var tempdate
                // var _this = this;
                this.getRequest("/lost/los/findAllHistoryLost?pageSize=" + this.pageSize + "&pageNum=" + this.pageNum).then(resp => {
                    this.tableLoading = false;
                    if (resp && resp.status == 200) {
                        this.total = resp.data.obj.total;
                        this.losts = resp.data.obj.data;
                        for (var i = 0; i < this.losts.length; i++) {
                            this.losts[i].listId = i + 1

                            tempdate =this.losts[i].createTime
                            this.losts[i].createTime=tempdate.slice(0,tempdate.indexOf("."))
                        }
                        this.clickAddButton=false;
                    }
                })
            },
            clearRecord(){
                this.deleteRequest("/lost/los/deleteAllHistory").then(resp=>{
                    this.tableLoading = false;
                    if (resp && resp.status == 200) {
                        this.initData();
                        Message.success({message: data.data.msg});
                    }
                })

            },
            clearForms(){
                this.lost={
                    id:'',
                    content: '',
                    creater: '',
                    createTime: '',
                }
            },
            handleSizeChange(val) {    //分页
                this.pageSize = val;
                this.initData()
            },
            handleCurrentChange(val) {  //分页
                this.pageNum = val;
                this.initData()
            },

        },
        mounted: function () {
            this.initData();
        },

    }
</script>

<style scoped>
  .firstSytle {
    margin-top: 30px;
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
  }
  .lastLine {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    margin:10px 0 10px 0;
  }

  .el-row {
    margin: 10px 0;
  }

  .el-table {
    text-align: left;
  }

</style>
